<template>
  <div class='sub-category'>
    <div class="container">
      <!-- 二级 -->
     <subBread/>
     <!-- 全部 规格 -->
     <subFilter/>
    <div class="goods-list">
     <!-- 创建排序组件 -->
     <subSort/>
     <!-- 商品列表 -->
     <subList/>
    </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, provide } from 'vue'
import { findSubCategoryFilter } from '@/api/category'
import { useRoute } from 'vue-router'
import subBread from './components/sub-bread.vue'
import subFilter from './components/sub-filter.vue'
import subSort from './components/sub-sort.vue'
import subList from './components/sub-list.vue'
export default {
  name: 'SubCategory',
  components: {
    subBread,
    subFilter,
    subSort,
    subList
  },
  setup () {
    const subCateData = ref({})
    const route = useRoute()
    provide('subCateData', subCateData)
    const filterParams = ref({
      // 筛选条件数据
      sortField: null, // 排序类别
      attrs: [], // 商品属性
      brandId: null // 品牌名称
    })
    provide('filterParams', filterParams)
    const getSubCateData = async () => {
      const { result } = await findSubCategoryFilter(route.params.id)

      result.brands.forEach(item => {
        item.selected = false
      })
      result.brands.unshift({
        id: null,
        name: '全部',
        selected: true
      })
      result.saleProperties.forEach(sale => {
        sale.properties.forEach(prop => {
          prop.selected = false
        })
        sale.properties.unshift({
          id: null,
          name: '全部',
          selected: true
        })
      })
      subCateData.value = result
    }
    onMounted(() => {
      getSubCateData(subCateData)
    })
    return {}
  }
}
</script>
<style scoped lang='less'>
.goods-list {
  background: #fff;
  padding: 0 25px;
  margin-top: 25px;
}
</style>
